package com.ate.aoligei.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.ate.aoligei.R;
import com.ate.aoligei.base.BaseActivity;
import com.ate.aoligei.contract.Contract;
import com.ate.aoligei.presenter.RegisterPresenter;

public class RegisterActivity extends BaseActivity implements Contract.RegisterView {

    @Override
    public int getLayoutId() {
        return R.layout.activity_register;
    }
    private EditText regisName;
    private EditText regisPwd;
    private Button register;
    RegisterPresenter presenter;
    @Override
    protected void init() {
        super.init();
        regisName = (EditText) findViewById(R.id.regis_name);
        regisPwd = (EditText) findViewById(R.id.regis_pwd);
        register = (Button) findViewById(R.id.register);
        presenter = new RegisterPresenter(this);
        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.register(regisName.getText().toString().trim(),regisPwd.getText().toString().trim());
                showProgress();
            }
        });
    }

    @Override
    public void onSuccess() {
        dismissProgress();
        Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void onError(String msg) {
        dismissProgress();
        Toast.makeText(this, "注册失败,"+msg, Toast.LENGTH_SHORT).show();

    }
}